<?php
require_once("includes/pagetop.php");
include_once("updates/CommonFeatures.php");
include_once("includes/common_snippets.php");

if(!isset($_SESSION['Allyfolio_User_ID']) || $_SESSION['Allyfolio_User_ID']==0)
{
    redirect("index.php");
}
try{

    $loggedUserObj=new UserDetails();
    if (!isset($_SESSION["User_details"])){
        $_SESSION["User_details"]=$loggedUserObj->getUserDetails($_SESSION["Allyfolio_User_ID"],true);
    }
    //$pset=$loggedUserObj->getUserPrivacyDetails($loggedUserObj->userId);
    $loggedUserObj=$_SESSION["User_details"];
    //$loggedUserObj->latestFriendNotificationsArr=array(1=>"sumer",2=>"vikas");
/*echo "<pre>";
print_r($loggedUserObj);
echo "</pre>";
*/
    
}
catch(Exception $ex){
    $logObj->writeException("home.php Exception: => ".$ex->getMessage());
    die("Home.php fetching user details".$ex->getMessage());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>AllyFolio | Page Photos </title>

<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />
<script src="js/general.js"></script>
<script src="js/functions.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>

<script src="js/jquery.placeholder.js"></script>

<link href="css/video-js.min.css" rel="stylesheet" type="text/css">
<script src="js/video.js"></script>
<!-- Unless using the CDN hosted version, update the URL to the Flash SWF -->
<script>
	videojs.options.flash.swf = "js/video-js.swf";
</script>

<script type="text/javascript" src="js/fancybox/jquery.fancybox.js?v=2.1.5"></script> 
<link rel="stylesheet" type="text/css" href="js/fancybox/jquery.fancybox.css?v=2.1.5" media="screen" /> 

	<div id="main_wrapper">
    <!--=================Header Start=======================-->
	<?php include_once "includes/header.php"; ?>
    <!--=================Header end=======================-->
    
    
    <script type="text/javascript">
    $(function() { $('input, textarea').placeholder();});
</script>
<style type="text/css">
    .chat_box{
        display:none;
    }
    .placeholder {
      color: #cccccc;
      }
</style>

<style type="text/css">
	.logo{ margin-top:10px;}
	.log_button{
	
	height:auto;
	margin:6px 0;
	overflow:hidden;
	float:left;
	margin-top:10px;
	
	}
	.new tr td{ vertical-align:top}
	
	textarea select{ border:1px solid #ccc}
	input textarea select{ border:1px solid #999}
    
    
</style>
<!-- custom post submission jquery by sujeet -->
<script src="js/autoloading.js"></script>
<script src="js/jquery.asyncpost.js"></script>
</head>

<body>
<?php
include_once "page_common.php";

//fetch pic details
$qryPageMedia="select * from af_company_page_media where Comp_Page_ID=:Comp_Page_ID and Status=1";
$arrPageMedia=$pdodbobj->fetch_array($pdodbobj->query($qryPageMedia,array(":Comp_Page_ID"=>$arrPageDetail[0]["Comp_Page_ID"])));
?>
    <!--=================Body Contain Start=======================-->
    <div class="wrapper">
    <?php include_once("page_top.php") ?>
      <div class="header">
        <div class="contain-wrap2 shadow" style="margin-top:30px; width:100%; ">
          
        <div class="home_left">
            <?php include_once("home_leftsidebar.php"); ?>
		</div>
		<div class="home_right">
		<table width="100%" border="0">
			<tr>
				<td>
					<table>
				        <tr>
				        	<td>
				        		<div class="upVidSec">
				        		<?php
				        			if($isPageOwner)
				        			{
				        		?>
							        <div class="upVid">
							       		<h5>
							       			<form enctype="multipart/form-data" id="image_form" name="image_form" method="post" >
							       				<a href="javascript:void(0);" onclick="return openFile();">Upload Video/Photos</a>
											   	<input type="file" name="selectedFile" id="selectedFile" style="display:block;" accept="video/*,image/*"  onChange="return upload();"/>
												 <div id="image_loader_div" style="display:none;"><img src="images/LoadingBar.gif" width="64px" height="64px"/></div>
												 <input type="hidden" name="page" id="page_upload_hidden" value="<?php echo $_REQUEST["page"]; ?>" />
											 </form>
										</h5>
							         </div> 
							         <script>
						        	function openFile()
									{
										$("#selectedFile").trigger("click");
										//document.getElementById('selectedFile').click(); 
									}
									
									function upload()
									{
										if(document.getElementById("selectedFile").value!="")
										{
											document.getElementById("image_loader_div").style.display="";
											formdata = false;
											if (window.FormData) {
												formdata = new FormData(document.getElementById("image_form"));
											}
										
											var xmlhttp;
													
											if (window.XMLHttpRequest)
											{// code for IE7+, Firefox, Chrome, Opera, Safari
												xmlhttp=new XMLHttpRequest();
											}
											else
											{// code for IE6, IE5
												xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
											}
											xmlhttp.onreadystatechange=function()
											{
												if (xmlhttp.readyState==4 && xmlhttp.status==200)
												{	
													var res=xmlhttp.responseText;	
													resArr=res.split("|~|");
													if(resArr[0]=="SUCCESS")
													{
														var divContent='<div class="upVid">';
														divContent +='<div class="vid"><a href="'+resArr[1]+'" class="PagePhotoGallery" data-fancybox-group="PagePhotoGallery"><img src="uploads/image_crop.php?image=/'+resArr[1]+'&width=93&height=91&cropratio=93:91" /></a></div>';
														divContent +='</div>';
														
														document.getElementById("page_photos_div").innerHTML=document.getElementById("page_photos_div").innerHTML+divContent;
														document.getElementById("image_loader_div").style.display="none";
													}
													else
													{
														document.getElementById("image_loader_div").style.display="none";
														alertify.alert(resArr[1]);
													}
												}
											}	
											xmlhttp.open("POST","ajax_page_photos.php",true);
											xmlhttp.send(formdata);
										}
									}
									
									function deletePageMedia(mediaID, page)
									{
										var xmlhttp;
													
										if (window.XMLHttpRequest)
										{// code for IE7+, Firefox, Chrome, Opera, Safari
											xmlhttp=new XMLHttpRequest();
										}
										else
										{// code for IE6, IE5
											xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
										}
										xmlhttp.onreadystatechange=function()
										{
											if (xmlhttp.readyState==4 && xmlhttp.status==200)
											{	
												var res=xmlhttp.responseText;	
												resArr=res.split("|~|");
												if(resArr[0]=="SUCCESS")
												{
													document.getElementById("media_upload_div_"+mediaID).innerHTML="";
													document.getElementById("media_upload_div_"+mediaID).style.display="none";
													document.getElementById("image_loader_div").style.display="none";
												}
												else
												{
													document.getElementById("image_loader_div").style.display="none";
													alertify.alert(resArr[1]);
												}
											}
										}	
										xmlhttp.open("POST","ajax_page_photos.php?purpose=delete&mediaID="+mediaID+"&page="+page,true);
										xmlhttp.send();
									}
						        </script>
							    <?php
							    	}
								?>     
							         <div class="clearfix"></div>
							         <div id="page_photos_div">
					 		<?php
					 			if(count($arrPageMedia)>0)
					 			{
					 				for($i=0; $i<count($arrPageMedia); $i++)
					 				{
					 					if(file_exists($arrPageMedia[$i]["Media_Path"]))
					 					{
					 						if($arrPageMedia[$i]["Media_Type"]=="IMAGE")
					 						{
							?>
									<div class="upVid" id="media_upload_div_<?php echo $arrPageMedia[$i]["Media_Upload_ID"]; ?>">
                     					<div class="vid"><a href="<?php echo $arrPageMedia[$i]["Media_Path"]; ?>" class="PagePhotoGallery" data-fancybox-group="PagePhotoGallery"><img src="<?php echo "uploads/image_crop.php?image=/".$arrPageMedia[$i]["Media_Path"]."&width=93&height=91&cropratio=93:91";  ?>" /></a></div>
		                     				<?php
		                     					if($isPageOwner)
		                     					{
											?>
										<a href="javascript:void(0)" onclick="return deletePageMedia('<?php echo $arrPageMedia[$i]["Media_Upload_ID"]; ?>','<?php echo $_REQUEST["page"]; ?>')" title="Delete"><img alt="X" src="images/closeBtn.png"></a>
											<?php		
												}
											 ?>	
                    					<!--<span style="text-shadow:none;">Adc</span>-->
                     				</div>
							<?php	
											}
											else
											{
										?>
											<video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="640" height="264" poster="http://video-js.zencoder.com/oceans-clip.png" data-setup="{}">
												<source src="<?php echo $arrPageMedia[$i]["Media_Path"]; ?>" type='video/mp4' />
												<source src="<?php echo $arrPageMedia[$i]["Media_Path"]; ?>" type='video/webm' />
												<source src="<?php echo $arrPageMedia[$i]["Media_Path"]; ?>" type='video/ogg' />
												<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>
											</video>
											<?php
		                     					if($isPageOwner)
		                     					{
											?>
										<a href="javascript:void(0)" onclick="return deletePageMedia('<?php echo $arrPageMedia[$i]["Media_Upload_ID"]; ?>','<?php echo $_REQUEST["page"]; ?>')" title="Delete"><img alt="X" src="images/closeBtn.png"></a>
											<?php		
												}
											 ?>	
										<?php		
											}
										}
									}	
								}
								else
								{
							?>
									Page Owner does not uploaded any media for this page.
							<?php		
								}
							 ?>		</div>
                    			</div>
				            </td>
				        </tr>
			        </table>		
				</td>
				<td width="15%" style="vertical-align:top;">
					<?php include_once "page_right_links.php"; ?>
				</td>
				<td></td>
			</tr>
		</table>
        
		</div> 
	   
	      
</div>

    </div>
    
    <div class="clearfix"></div>
    <!--=================Body Contain end=======================-->
    </div>

    <div class="clearfix"></div>
    <?php include_once "includes/footer.php"; ?>
</div>
    <!--=================Footer end=======================--> 
</body>
</html>
<script>
<?php
if(isset($msg_success) && $msg_success!="")
{
    ?>
    alertify.alert("<?php echo $msg_success; ?>");
    <?php
}

if(isset($msg_error) && $msg_error!="")
{
    ?>
    alertify.alert("<?php echo $msg_error; ?>");
    <?php
}
?>

$(document).ready(function(){
	$('.PagePhotoGallery').fancybox();
});
</script>
